package ACwing.P4Math.Combinatorial_Number;

import java.io.*;

/**
 * @Date : 2023-03-24
 * @Description:885. 求组合数 I    预处理
 * C62=6x5/2x1
 * Cab=Ca-1 b +Ca-1 b-1
 * 询问次数一般，数的范围小    递推   O（n^2)
 */
public class CN01 {
    static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(System.out));
    static int n;
    static int N=2010;
    static int mod= (int) (1e9+7);
    static int [][]c=new int[N][N];//预处理组合数所有的情况
    static void init(){
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <=i; j++) {
                if(j==0) c[i][j]=1;//处理边界
                else c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
            }
        }
    }
    public static void main(String[] args) throws IOException {
        init();
        n=Integer.parseInt(br.readLine());
        int a,b;
        while (n--!=0){
            String[] strings = br.readLine().split("\\s+");
            a=Integer.parseInt(strings[0]);
            b=Integer.parseInt(strings[1]);
            bw.write(String.valueOf(c[a][b]));
            bw.newLine();
        }
        bw.flush();
    }
}
